package com.example.boot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.pojo.entity.Template;
import com.example.pojo.vo.ApproverVO;
import com.example.service.TemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审批模版相关接口
 *
 * @author ding
 * @since 2024/7/12
 */
@RestController
@RequestMapping("/template")
@Api(tags = "审批模版接口")
public class TemplateController {

    @Autowired
    private TemplateService templateService;

//    @PreAuthorize("hasAuthority('TEMPLATE_ADD')")
    @PostMapping("/add")
    public Result addTemplate(@RequestBody Template template) {
        templateService.addTemplate(template);
        return Result.success();
    }

//    @PreAuthorize("hasAuthority('TEMPLATE_DELETE')")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        templateService.delete(id);
        return Result.success();
    }

    @ApiOperation("获取审批人列表")
//    @PreAuthorize("hasAuthority('TEMPLATE_ADD')")
    @GetMapping("/getApprover")
    public Result getApprover() {
        List<ApproverVO> approver = templateService.getApprover();
        return Result.success(approver);
    }

    @ApiOperation("分页查询模版信息")
//    @PreAuthorize("hasAuthority('TEMPLATE_PAGEQUERY')")
    @GetMapping("/page")
    public Result page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize
    ){
        Page<Template> page = templateService.selectPage(pageNum, pageSize);
        return Result.success(page);
    }

    @ApiOperation("根据模版id获取模版信息")
//    @PreAuthorize("hasAuthority('TEMPLATE_QUERY')")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Template template = templateService.selectById(id);
        return Result.success(template);
    }

    @ApiOperation("启用禁用模版")
//    @PreAuthorize("hasAuthority('TEMPLATE_EDIT')")
    @PutMapping("/setStatus")
    public Result setStatus(@RequestBody  Template template) {
        templateService.setStatus(template);
        return Result.success();
    }


}
